package com.wwwarehouse.contract.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.wwwarehouse.common.common.Common;
import com.wwwarehouse.common.tools.rsa.StringUtils;
import com.wwwarehouse.contract.bean.CreateWarehouseMapTaskBean;
import com.wwwarehouse.contract.bean.ListCreateWarehouseMapBean;
import com.wwwarehouse.contract.program_operation.ArithUtil;

import java.util.ArrayList;
import java.util.List;

import contract.wwwarehouse.com.contract.R;

/**
 * Created by feng.gao on 2017/10/17.
 */

public class CreateWarehouseMapAdapter extends BaseAdapter {
	private List<ListCreateWarehouseMapBean.ListBean> list = new ArrayList<>();
	private Context mContext;
	private int mHeight;

	public CreateWarehouseMapAdapter(List<ListCreateWarehouseMapBean.ListBean> list, Context mContext , int mHeight) {
		this.list = list;
		this.mContext = mContext;
		this.mHeight = mHeight;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = View.inflate(mContext, R.layout.create_warehouse_map_item_layout, null);
			holder.mMapNameTv = (TextView) convertView.findViewById(R.id.map_name_tv);
			holder.mFloorTv = (TextView) convertView.findViewById(R.id.floor_tv);
			holder.mIv = (ImageView) convertView.findViewById(R.id.iv);
			holder.mNameTv = (TextView) convertView.findViewById(R.id.name_tv);
			holder.mConversionTv = (TextView) convertView.findViewById(R.id.conversion_tv);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		if (list.size() > 0) {
			holder.mMapNameTv.setText(list.get(position).getName());
			holder.mNameTv.setText(list.get(position).getName());
			holder.mFloorTv.setText(StringUtils.getResourceStr(mContext, R.string.floor_num, list.get(position).getNum()));
			holder.mConversionTv.setText(StringUtils.getResourceStr(mContext, R.string.conversion_ratio_content, list.get(position).getScale()));
			AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
					LinearLayout.LayoutParams.MATCH_PARENT, mHeight / 3);

			convertView.setLayoutParams(lp);
		}
		return convertView;
	}

	public class ViewHolder {
		private TextView mMapNameTv;
		private TextView mFloorTv;
		private ImageView mIv;
		private TextView mNameTv;
		private TextView mConversionTv;

	}
}
